package com.xtt._04_Apache.commons_text;

import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.text.WordUtils;
import org.junit.Test;

/**
 * @Author xtt.
 * @Description: commons-text
 * @Date:Create in 2017/9/26 0026 下午 21:44
 * @Modify By:
 */
public class TextTest {
    /**
     * WordUtils
     */
    @Test
    public void testWordUtils() {
        System.out.println("空格间首字母大写");
        System.out.println(WordUtils.capitalize("i am FINE"));//I Am FINE
        WordUtils.uncapitalize(null);        // null
        WordUtils.uncapitalize("");         // ""
        WordUtils.uncapitalize("I Am FINE"); // "i am fINE"
        //containsAllWords
        WordUtils.containsAllWords(null, "123");            // false
        WordUtils.containsAllWords("", "123");              // false
        WordUtils.containsAllWords("123", null);            // false
        WordUtils.containsAllWords("abcd", "ab", "cd"); //false
        WordUtils.containsAllWords("abc def", "def", "abc"); //true

        //initials
        WordUtils.initials(null);             // null
        WordUtils.initials("");               // ""
        WordUtils.initials("Ben John Lee");   // "BJL"
        WordUtils.initials("Ben J.Lee");      // "BJ"

        WordUtils.initials("Ben John Lee", null);   // "BJL"
        WordUtils.initials("Ben J.Lee", null);      // "BJ"
        System.out.println(WordUtils.initials("Ben J.Lee", ' ','.')); // "BJL"
        WordUtils.initials("123", new char[0]);        // ""
        //wrap 指定column开始换行
        System.out.println(WordUtils.wrap("Here is one line of text that is going to be wrapped after 20 columns.",20));
//        Here is one line of
//        text that is going
//        to be wrapped after
//        20 columns.
        System.out.println(
                WordUtils.wrap("Here is one line of text that is going to be wrapped after 20 columns.",20,"<br />",false)
        );//Here is one line of<br />text that is going<br />to be wrapped after<br />20 columns.

    }

    /**
     * StringEscapeUtils
     */
    @Test
    public void testStringEscapeUtils() {
        //转译js
        System.out.println(StringEscapeUtils.escapeEcmaScript("He didn't say, 'Stop!'"));//He didn\'t say, \'Stop!\'
        System.out.println(StringEscapeUtils.unescapeEcmaScript("He didn\'t say, \'Stop!\'"));//He didn't say, 'Stop!'
        //转译html
        System.out.println(StringEscapeUtils.escapeHtml4("&lt;Fran&ccedil;ais&gt;"));//&amp;lt;Fran&amp;ccedil;ais&amp;gt;
        System.out.println(StringEscapeUtils.unescapeHtml4("&amp;lt;Fran&amp;ccedil;ais&amp;gt;"));//&lt;Fran&ccedil;ais&gt;
    }
}
